
%MACRO ALGORSEBORG (DATA=, ID=, VAR=, IDENT='EST', ALFA=0.5,
				SIM_COMBINADA=SIM_COMBINADA,
				DIST_MAH=DIST_MAH, SIM_MAH=SIM_MAH, SIM_COMP=SIM_COMP, landas=1, 
				metodosinghal=0	); 
	
     %PREPARADIST (DATA=&DATA, ID=&ID , VAR=&VAR ,
						MATCOMPONENTES=SALIDA2, NCOMPOS=NCOMPOS, fijados=0);
	
    %MEDIA_VAR_N (DATA=&DATA, VAR=&VAR, ID=&ID, 
	VECMEDIAS=VECTORMEDIAS, NVALIDOS=N_VALIDOS, COVAR=COVARIANZAS);


%DISTsinghal (data1=SALIDA2, data2=salida2, id1=&ID, id2=&id, var=&var,
			IDENT1=&IDENT , IDENT2=&IDENT, similitud=&SIM_COMP); /***CAMBIAR IDENT 
																		CUANDO PROCEDA'*/ 

%distmahala (DATAMEDIAS1=VECTORMEDIAS, DATACOVAR1=COVARIANZAS, DATAN1=n_VALIDOS,
			DATAMEDIAS2=VECTORMEDIAS, DATACOVAR2=COVARIANZAS, DATAN2=n_VALIDOS,
			ID1=&ID , ID2=&ID, IDENT1=&ident,IDENT2=&ident, VAR=&VAR,  
					MAHALANOB=&DIST_MAH	, SIMILMAH=&SIM_MAH ) ;

%if &metodosinghal=1 %then %do; 
	data similb; set sim_javier;run;
	%end; 
%else %do; 
	data similb; set &sim_mah;run;
	%end;

  /**COMBINAR LAS SIMILITUDES ****/
%if &landas=1 %then %do; 
PROC IML; 
  	  USE Similb; 
	  READ ALL var {filas} into filas; 
	  READ ALL VAR _NUM_  INTO MAH; 
  
	

	  USE SIMIL_Conlanda; 
	  READ ALL VAR _NUM_ INTO COMP; 

	  COM=&ALFA*(MAH)+ (1-&ALFA)*COMP; 

	FILAS=T(filas);

create &sim_COMBINADA from com [ROWNAME=FILAS COLNAME=FILAS];
append from com [ROWNAME=FILAS]; 
close  &sim_combinada;
quit; 

%end;
%else %do;
PROC IML; 
  	  USE &SIM_MAH; 
	  READ ALL var {filas} into filas; 
	  READ ALL VAR _NUM_  INTO MAH; 
  
	

		USE &SIM_COMP; 
	  READ ALL VAR _NUM_ INTO COMP; 

	  COM=&ALFA*(MAH)+ (1-&ALFA)*COMP; 

	FILAS=T(filas);

create &sim_COMBINADA from com [ROWNAME=FILAS COLNAME=FILAS];
append from com [ROWNAME=FILAS]; 
close  &sim_combinada;
quit; 
%end;

TITLE 'SIMILITUD BASADA EN DATOS COMBINADOS';
proc print data=&sim_combinada;run;

%MEND ALGORSEBORG;
